<?php
/**
 * 
 * @author huangyusheng
 * @since 2014-3-7
 * @package project_name.package_name
 */
abstract class PfinalModelAbstract {
	// TODO - Insert your code here
	protected $activeRecord;
	
	protected $selectorChain;
	
	public function __construct(){
		$this->activeRecord = new Pfinal_Model_ActiveRecord();
	}
	
	/**
	 * 获取通用的activeRecord操作类
	 * @param Pfinal_Model_Adapter_Interface $adapter
	 */
	public function select(Pfinal_Model_Adapter_Interface $adapter = null){
		if (null === $adapter){
			$adapter = new Pfinal_Model_Adapter_RMDBS();
		}
		$selector = new Pfinal_Model_Selector($adapter);
		return $selector;
	}
	
	/**
	 * 获取多表连接操作handler
	 * @return Pfinal_Model_SelectorChain
	 */
	public function beginQuery(){
		$this->selectorChain = new Pfinal_Model_SelectorChain();
		return $this->selectorChain;
	}
	
	/**
	 * 
	 * @param Pfinal_Model_SelectorChain $chain
	 * @param Pfinal_Model_Optimizer_Interface $optimizer
	 * @return [type]
	 */
	public function query(Pfinal_Model_SelectorChain $chain,Pfinal_Model_Optimizer_Interface $optimizer = null){
		return $this->activeRecord->doQuery($chain,$optimizer);
	}
	
	
}

?>